/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pabudr_se;

import java.awt.Color;
import java.util.ArrayList;

/**
 *
 * @author Drzycimski
 */
public class TestSimulator {

    public static final void main(String[] args) {
        AtomPanel panel = AtomPanel.getAtomPanel();
        Simulator sim = new Simulator(panel);

        boolean intersect, kollision, wand, ecke;

        System.out.println("Teste Barrier-Atom Intersect");
        intersect = TestIntersect(sim);
        if (!intersect)
            System.out.println("Fehler in Intersect");

        System.out.println("Teste Atom-Atom Kollision");
        kollision = TestKollision(sim);
        if (!kollision)
            System.out.println("Fehler in Atom-Atom Kollision");

        System.out.println("Teste Wand Kollision");
        wand = TestWand(sim);
        if (!wand)
            System.out.println("Fehler in Wand Kollision");

        System.out.println("Teste Wand Kollision in der Ecke");
        ecke = TestEcke(sim);
        if (!ecke)
            System.out.println("Fehler in Wand-Ecke Kollision");

        if (intersect && kollision && wand && ecke)
            System.out.println("Alle Tests erfolgreich!");

    }

    private static final Atom getAtom(float x, float y, float r)
    {
        return new Atom(x, y, 1, 1, r, r, Atom.DEFAULTCOLOR);
    }

    /**
     * Teste die Ueberschneidung von Atom und Barriere
     * @param sim
     * @return
     */
    private static final boolean TestIntersect(Simulator sim)
    {
        int count = 0;
        Barrier b = new Barrier(0, 0, 200, 200);

        if (!sim.barrierAtomIntersect(getAtom(10,100,10), b))
            ++count;

        if (!sim.barrierAtomIntersect(getAtom(300,300,10), b))
            ++count;

        if (sim.barrierAtomIntersect(getAtom(100,100,10), b))
            ++count;

        return count == 3;
    }

    private static final boolean TestKollision(Simulator sim)
    {
        int count = 0;
        ArrayList<Atom> atomListe = sim.list_atome;

        if (!sim.atomkollision(getAtom(100, 100, 10), true))
            ++count;

        atomListe.add(getAtom(200, 200, 10));
        if (!sim.atomkollision(getAtom(100, 100, 10), true))
            ++count;

        atomListe.add(getAtom(105, 105, 10));
        if (sim.atomkollision(getAtom(100, 100, 10), true))
            ++count;

        atomListe.clear();

        return count == 3;
    }

    private static final boolean TestWand(Simulator sim)
    {
        int count = 0;
        sim.atomPanel.setSize(200, 200);

        Atom a = getAtom(50,100,10);
        a.vx = 1;
        a.vy = 1;

        while(!sim.wandkollision(a, false))
        {
            a.move();
        }
        if (a.vy == -1 && a.vx == 1)
            ++count;

        while(!sim.wandkollision(a, false))
        {
            a.move();
        }
        if (a.vy == -1 && a.vx == -1)
            ++count;

        while(!sim.wandkollision(a, false))
        {
            a.move();
        }
        if (a.vy == 1 && a.vx == -1)
            ++count;

        while(!sim.wandkollision(a, false))
        {
            a.move();
        }
        if (a.vy == 1 && a.vx == 1)
            ++count;

        return count == 4;
    }

    private static final boolean TestEcke(Simulator sim)
    {
        int count = 0;
        sim.atomPanel.setSize(200, 200);

        for (int i = -1; i < 2; i += 2)
            for (int j = -1; j < 2; j += 2)
            {
                Atom a = getAtom(100,100,10);
                a.vx = i;
                a.vy = j;

                for (int x = 0; x < 200/Atom.SLOWFACTOR; ++x)
                {
                    a.move();
                    sim.wandkollision(a, false);
                }

                if (a.vx == -i && a.vy == -j)
                    ++count;

            }

        return count == 4;
    }
}
